package com.hsylient.javase.chapter10;

import org.junit.Test;

public class MyMath {

    @Test
    public void testField() {
        System.out.println(Math.E);
        System.out.println(Math.PI);
    }

    @Test
    public void testSin() {
        System.out.println(Math.sin(Math.toRadians(30.0)));
    }

    @Test
    public void testCos() {
        System.out.println(Math.cos(Math.toRadians(60.0)));
    }

    @Test
    public void testTan() {
        System.out.println(Math.sin(Math.toRadians(30.0)));
    }

    @Test
    public void testExp() {
        System.out.println(Math.exp(2)); // e的平方
    }

    @Test
    public void testLog() {
        System.out.println(Math.log(Math.exp(5)));
    }

    @Test
    public void testLog10() {
        System.out.println(Math.log10(100.0));
    }

    @Test
    public void testSqrt() {
        System.out.println(Math.sqrt(4.0));
        System.out.println(Math.sqrt(-2));
    }

    @Test
    public void testCbrt() {
        System.out.println(Math.cbrt(27.0));
    }

    @Test
    public void testIEEEremainder() {
        System.out.println(Math.IEEEremainder(13.0, 2.0));
    }

    @Test
    public void testCeil() {
        System.out.println(Math.ceil(23.342342));
    }

    @Test
    public void testFloor() {
        System.out.println(Math.floor(12.2121));
    }

    @Test
    public void testRint() {
        System.out.println(Math.rint(12.612));
    }

    @Test
    public void testAtan2() {
        System.out.println(Math.atan2(1, Math.sqrt(3.0)));
    }

    @Test
    public void testPow() {
        System.out.println(Math.pow(2.0, 2.0));
    }

    /**
     * 小数四舍五入到整数
     */
    @Test
    public void testRound() {
        System.out.println(Math.round(21.6121F));
    }

    @Test
    public void testRandom() {
        System.out.println(Math.random());
    }

    @Test
    public void testAddExact() {
        // TODO java中的异或运算
        // 超出int边界报错
        System.out.println(Math.addExact(1, -2147483648));
        System.out.println(Math.addExact(1L, Long.MAX_VALUE));
    }

    @Test
    public void testSubtractExact() {
        System.out.println(Math.subtractExact(-10, Integer.MAX_VALUE));
        System.out.println(Math.subtractExact(-10L, Integer.MAX_VALUE));
    }

    @Test
    public void testMultiplyExact() {
        System.out.println(Math.multiplyExact(100, Integer.MAX_VALUE));
        System.out.println(Math.multiplyExact(100L, Integer.MAX_VALUE));
    }

    @Test
    public void testIncrementExact() {
        System.out.println(Math.incrementExact(12));
        System.out.println(Math.incrementExact(12L));
        System.out.println(Math.incrementExact(Integer.MAX_VALUE));
    }

    @Test
    public void testDecrementExact() {
        System.out.println(Math.decrementExact(12));
        System.out.println(Math.decrementExact(12L));
        System.out.println(Math.decrementExact(Integer.MIN_VALUE));
    }

    @Test
    public void testNegateExact() {
        System.out.println(Math.negateExact(12));
        System.out.println(Math.negateExact(-12L));
    }

    @Test
    public void testToIntExact() {
        System.out.println(Math.toIntExact(12L));
    }

    @Test
    public void testMultiplyFull() {
        System.out.println(Math.multiplyFull(12, 12));
        System.out.println(Math.multiplyHigh(12L, 12L));
    }

    @Test
    public void testFloorDiv() {
        System.out.println(Math.floorDiv(23, 2));
        System.out.println(Math.floorDiv(23L, 2));
        System.out.println(Math.floorDiv(23L, 2L));
        System.out.println(Math.floorMod(12, 13));
    }

    /**
     * 取绝对值
     */
    @Test
    public void testAbs() {
        System.out.println(Math.abs(-12));
    }

    @Test
    public void testMax() {
        System.out.println(Math.max(3, -5));
    }
}
